﻿package {
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	/**
	 * ...
	 * @author kot
	 * мяу
	 */
	public class Knight extends Figure {
		
		override public function toString():String {
			return "Knight";
		}
		
		override public function getAvailableMoves(): int {
			moves = new Array();
			for (var x = -2; x < 3; x++) {
				for (var y = -2; y < 3; y++) {
					if (((Math.abs(x) == 2  && Math.abs(y) == 1) || (Math.abs(x) == 1  && Math.abs(y) == 2)) 
						&& (checkCell(x +figureX, y + figureY)) ) {
						moves.push(new Point(x + figureX, y + figureY));
					}
				}
			}
			return moves.length;
		}
		
		override public function canMove(x : int, y : int) : Boolean {
			if (figureX == x && figureY == y)
				return true;
			for (var xx = -2; xx < 3; xx++) {
				for (var yy = -2; yy < 3; yy++) {
					if (((Math.abs(xx) == 2  && Math.abs(yy) == 1) || (Math.abs(xx) == 1  && Math.abs(yy) == 2))
						&& xx + figureX == x && yy + figureY == y) {
						return true;
					}
				}
			}
			return false;
		}
	}
}